package com.ruoyi.wapp.controller;

import com.ruoyi.common.constant.CacheKeyConstants;
import com.ruoyi.system.domain.WdyProduct;
import com.ruoyi.system.service.IWdyProductService;
import com.ruoyi.wapp.controller.base.BaseController;
import com.ruoyi.wapp.controller.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class WdyProductController extends BaseController {
    @Autowired
    private IWdyProductService wdyProductService;
    @GetMapping("/getProduct")
    public Result getProduct(long id) {
        String cacheKey = CacheKeyConstants.getTempletString(CacheKeyConstants.PRODUCT, String.valueOf(id));
        WdyProduct product = (WdyProduct) redisTemplate.opsForValue().get(cacheKey);
        if(product == null) {
            product = wdyProductService.getById(id);
            if(product != null) {
                redisTemplate.opsForValue().set(cacheKey, product);
            }
        }
        return Result.ok().put("product", product);
    }
}
